package com.cloudsigns.factorymanager2.engineering.activity;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.bean.EngineeringInstallationOrderBean;
import com.cloudsigns.factorymanager2.engineering.customview.ReadDilalog;
import com.cloudsigns.factorymanager2.project.adapter.EngineeringInformationAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 工程 工单管理 编辑工单 批量安装  工程详情
 * Created by tony on 2018/1/31.
 */

public class EditBatchInstallationEngineeringDetailActivity extends Activity implements View.OnClickListener, AdapterView.OnItemClickListener {
    private ImageView img_back;
    private TextView tv_title;
    private ListView lv;
    private ReadDilalog engineeringDialog;
    private EngineeringInformationAdapter adapter;
    private List<EngineeringInstallationOrderBean> engineeringBeanList = new ArrayList<>();
    private final String TAG = EditBatchInstallationEngineeringDetailActivity.class.getSimpleName();


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.layout_edit_batch_installation_engineering_detail);

        init();
    }

    private void init() {
        img_back = findViewById(R.id.img_back);
        tv_title = findViewById(R.id.tv_title);
        lv = findViewById(R.id.lv);


        tv_title.setText(getResources().getText(R.string.batch_installation));

        img_back.setOnClickListener(this);


        engineeringBeanList.add(new EngineeringInstallationOrderBean());
        engineeringBeanList.add(new EngineeringInstallationOrderBean());
        engineeringBeanList.add(new EngineeringInstallationOrderBean());
        engineeringBeanList.add(new EngineeringInstallationOrderBean());


        adapter = new EngineeringInformationAdapter(this, TAG);
        adapter.setData(engineeringBeanList);
        lv.setAdapter(adapter);

        lv.setOnItemClickListener(this);
    }



    private void showEngineeringInfoDialog(int positon) {
        EngineeringInstallationOrderBean bean = engineeringBeanList.get(positon);
        engineeringDialog = new ReadDilalog(this);
        engineeringDialog.createEngineeringInfoDialog("",null);

        engineeringDialog.show();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (engineeringDialog != null) {
            engineeringDialog.dismiss();
            engineeringDialog = null;
        }


    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

        showEngineeringInfoDialog(i);
    }

    @Override
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;

        }
    }
}
